package cn.ante.mq;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        // 创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("producer_sync_group");
        // 创建连接nameserver
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动实例
        producer.start();
        // 创建消息、主题、tag、消息体
        Message message = new Message("order","productorder","我是一个服务订单".getBytes(StandardCharsets.UTF_8));
        // 发送消息到broker
        SendResult result = producer.send(message);
        System.out.println(result);

        // 关闭生产者
        producer.shutdown();


    }
}
